export default {
	namespaced:true,
	
	state: () => ({
		address:JSON.parse(uni.getStorageSync('address') || '{}'),
		token: uni.getStorageSync('token') || '',
		userInfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
		// 重定向的对象 {openType跳转方式, from来自那个页面 }
		redirectInfo: null
	}),
	
	mutations:{
		// 更新收货地址
		updateAddress(state, address){
			state.address = address
			this.commit('m_user/saveAddressToStorage')
		},
		// 更新用户信息
		updataUserInfo(state, userinfo){
			state.userInfo = userinfo
			this.commit('m_user/saveUserInfoToStorage')
		},
		
		// 保存地址到本地
		saveAddressToStorage(state){
			uni.setStorageSync('address', JSON.stringify(state.address))
		},
		// 保存用户信息到本地
		saveUserInfoToStorage(state){
			uni.setStorageSync('userinfo', JSON.stringify(state.userInfo))
		},
		// 更新token
		updateToken(state, token){
			state.token = token
			this.commit('m_user/saveTokenToStorage')
		},
		// 将token保存到本地
		saveTokenToStorage(state){
			uni.setStorageSync('token', state.token)
		},
		// 更新重定向的值
		updateRedirectInfo(state, redirectinfo){
			state.redirectInfo = redirectinfo
			// this.commit('m_user/saveRedirectInfoToStorage')
		},
		// 将重定向信息保存到本地
		// saveRedirectInfoToStorage(state){
		// 	uni.setStorageSync('redirectinfo', JSON.stringify(state.redirectInfo))
		// }
	},
	getters:{
		addstr(state){
			if(!state.address.provinceName) return ''
			
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
		}
	}
}